/**
 * 处理文章相关操作
 */

import ajax from '@/utils/request';

/**
 * 根据频道id获取某个频道文章列表
 * @param {*} channelId 频道id
 * @param {*} timestamp 时间戳，注意该参数，当前请求时，要传入上一次请求回来的timestamp，以取到正确的数据
 */
export const getArticles = (channelId, timestamp) => {
  return ajax({
    method: 'GET',
    url: '/app/v1_1/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp,
      with_top: 1
    }
  });
};

/**
 * 文章更多操作，不感兴趣指定ID的文章
 * @param {*} articleId 不喜欢的文章id
 */
export const dislikeArticle = articleId => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/dislikes',
    data: {
      target: articleId
    }
  });
};

/**
 * 举报文章
 * @param {*} articleId 文章id
 * @param {*} type 举报类型编号
 */
export const reportArticle = (articleId, type) => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/reports',
    data: {
      target: articleId,
      type
    }
  });
};

/**
 * 获取文章详情
 * @param {*} id 文章ID
 */
export const getArticle = id => {
  return ajax({
    method: 'GET',
    url: `/app/v1_0/articles/${id}`
  });
};

/**
 * 对文章点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/likings',
    data: {
      target: id
    }
  });
};

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return ajax({
    method: 'DELETE',
    url: `/app/v1_0/article/likings/${id}`
  });
};

/**
 * 不喜欢
 * @param {*} id 文章编号
 */
export const addDislike = id => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/dislikes',
    data: {
      target: id
    }
  });
};

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDislike = id => {
  return ajax({
    method: 'DELETE',
    url: `/app/v1_0/article/dislikes/${id}`
  });
};
